#include "Setting.h"
#include <QDataStream>
#include <QApplication>
#include <QFile>

QDataStream &operator << (QDataStream &s, const Setting &param)
{
	s << param.dllType;
	s << param.ICDLL_dbtype;
	s << param.ICDLL_dbpath;
	s << param.V9RF_coid;

	s << param.cardType;
	s << param.CVR100UD_type;
	s << param.CVR100UD_usb;
	s << param.CVR100UD_uart;

	s << param.RFV42DLL_com;
	s << param.RFV42DLL_sysNo;
	s << param.ProUSb_coID;

	return s;
}

QDataStream &operator >> (QDataStream &s, Setting &param)
{
	s >> param.dllType;
	s >> param.ICDLL_dbtype;
	s >> param.ICDLL_dbpath;
	s >> param.V9RF_coid;
	
	s >> param.cardType;
	s >> param.CVR100UD_type;
	s >> param.CVR100UD_usb;
	s >> param.CVR100UD_uart;
	
	s >> param.RFV42DLL_com;
	s >> param.RFV42DLL_sysNo;
	s >> param.ProUSb_coID;

	return s;
}

Setting g_setting;
Setting::Setting()
{
	dllType = 0;
	ICDLL_dbtype = 0;	
	TPDLL_type = 1;

	cardType = 0;
	CVR100UD_type = 0;
	CVR100UD_usb = 0;
	CVR100UD_uart = 0;

	RFV42DLL_com = 0;
	RFV42DLL_sysNo = 0;
	ProUSb_coID = 0;
}

void Setting::save()
{
	QString filename = QApplication::applicationDirPath() + "/setting.dat";
	QFile file(filename);
	if (file.open(QFile::WriteOnly | QFile::Truncate))
	{
		QDataStream s(&file);
		s << *this;		

		file.close();
	}	
}

void Setting::load()
{
	QString filename = QApplication::applicationDirPath() + "/setting.dat";
	QFile file(filename);
	if (file.open(QFile::ReadOnly))
	{		
		QDataStream s(&file);
		s >> *this;		

		file.close();
	}

	if(dllType < 0)
		dllType = 0;
	if(cardType < 0)
		cardType = 0;
}